summaryrefslogtreecommitdiffstats
path: root/Dockerfile
blob: 24eb5a108a626156310d0dafe6104b6f00572ae8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# SPDX-License-Identifier: AGPL-3.0-or-later

FROM alpine AS stage-alpine

# alpine - Official Image | Docker Hub
# https://hub.docker.com/_/alpine

WORKDIR /app/

# Install all dependencies, including Wget, Rust, Docusaurus, and other required packages.

RUN \
apk \
-- \
add \
wget \
gcc \
rustup \
npm \
;

# Install the dependencies of Docusaurus and Typescript.

COPY \
./docusaurus/package.json \
./docusaurus/package.json

RUN \
npm \
--prefix ./docusaurus/ \
-- \
install \
;

RUN \
npm \
--prefix ./docusaurus/ \
-- \
audit \
fix \
;

COPY \
./typescript/package.json \
./typescript/package.json

RUN \
npm \
--prefix ./typescript/ \
-- \
install \
;

RUN \
npm \
--prefix ./typescript/ \
-- \
audit \
fix \
;

# Set up the Rust compiler.

RUN \
rustup-init \
-y \
-- \
;

# Download the necessary dependencies for the Rust programs.

COPY \
./rust/wolfree_download_dependencies/ \
./rust/wolfree_download_dependencies/

RUN \
PATH="$HOME/.cargo/bin:$PATH" \
cargo \
-- \
clippy \
--manifest-path ./rust/wolfree_download_dependencies/Cargo.toml \ 
-- \
--warn clippy::all \
--warn clippy::cargo \
--warn clippy::nursery \
--warn clippy::pedantic \
--warn clippy::restriction \
;

RUN \
PATH="$HOME/.cargo/bin:$PATH" \
cargo \
run \
--manifest-path ./rust/wolfree_download_dependencies/Cargo.toml \
-- \
;

# Cloudflare and WolframAlpha are invaluable tools for web developers,
# providing easy access to prebuilt JavaScript files.
# To effortlessly obtain these files, you can utilize the Wget command-line utility.
# Cloudflare's web servers offer a vast collection of popular JavaScript libraries.
# On the other hand,
# WolframAlpha's web servers specifically host the essential JavaScript files for the 2-dimensional math input editor.

RUN \
wget \
--directory-prefix=./docusaurus/static/ \
--no-host-directories \
--page-requisites \
--convert-links \
--no-verbose \
--input-file=- \
--base= \
-- \
'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js' \
'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.map' \
'https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.0.5/purify.min.js' \
'https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.0.5/purify.min.js.map' \
'https://www.wolframalpha.com/input/index.html' \
; \
: \
;

# We use the Sed command to extract the pathnames from the "Webpack" and "buildManifest" files.
# After successfully parsing the pathnames, we proceed to download the files using the Wget command.

RUN \
sed \
-e 's|.*js...static.chunks...........||' \
-e 's|"........js.....miniCssF.*|.js\n|' \
-e 's|:"|.|g' \
-e 's|",|.js\n|g' \
-- \
./docusaurus/static/_next/static/chunks/webpack-*.js \
| \
wget \
--directory-prefix=./docusaurus/static/ \
--no-host-directories \
--page-requisites \
--convert-links \
--no-verbose \
--input-file=- \
--base=https://www.wolframalpha.com/_next/static/chunks/ \
-- \
; \
: \
;

RUN \
sed \
-e 's|.*return.static.css.....||' \
-e 's|.........css.......function.*|.css\n|' \
-e 's|[0-9]*:"||g' \
-e 's|",|.css\n|g' \
-- \
./docusaurus/static/_next/static/chunks/webpack-*.js \
| \
wget \
--directory-prefix=./docusaurus/static/ \
--no-host-directories \
--page-requisites \
--convert-links \
--no-verbose \
--input-file=- \
--base=https://www.wolframalpha.com/_next/static/css/ \
-- \
; \
: \
;

RUN \
sed \
-e 's|.*sortedPages.*}..||' \
-e 's|...self.__BUILD_MANIFEST_CB&&self.__BUILD_MANIFEST_CB.*||' \
-e 's|","|\n|g' \
-- \
./docusaurus/static/_next/static/*/_buildManifest.js \
| \
wget \
--directory-prefix=./docusaurus/static/ \
--no-host-directories \
--page-requisites \
--convert-links \
--no-verbose \
--input-file=- \
--base=https://www.wolframalpha.com/_next/ \
-- \
; \
: \
;

# Remove unused large files,
# such as decorative images,
# from the static website.

RUN \
truncate \
-s 0 \
-- \
./docusaurus/static/_next/static/images/* \
./docusaurus/static/_next/static/media/*.png \
./docusaurus/static/_next/static/media/*.gif \
;

# Compile and execute the Rust program.
# The Rust program allows customization of the static pages downloaded with Wget.

COPY \
./rust/wolfree_sed_in_place/ \
./rust/wolfree_sed_in_place/

RUN \
PATH="$HOME/.cargo/bin:$PATH" \
cargo \
-- \
clippy \
--manifest-path ./rust/wolfree_sed_in_place/Cargo.toml \
-- \
--warn clippy::all \
--warn clippy::cargo \
--warn clippy::nursery \
--warn clippy::pedantic \
--warn clippy::restriction \
;

RUN \
PATH="$HOME/.cargo/bin:$PATH" \
cargo run \
--manifest-path ./rust/wolfree_sed_in_place/Cargo.toml \
-- \
;

# Compile the Typescript files and output the JavaScript files.

COPY \
./typescript/ \
./typescript/

RUN \
npm \
--prefix ./typescript/ \
-- \
exec \
tsc \
--project ./typescript/ \
;

# Preprocess MDX files.

COPY \
./docusaurus/ \
./docusaurus/

# Run the Rust program to customize the Docusaurus pages.

COPY \
./rust/wolfree_patch_libredirect/ \
./rust/wolfree_patch_libredirect/

RUN \
PATH="$HOME/.cargo/bin:$PATH" \
cargo \
-- \
clippy \
--manifest-path ./rust/wolfree_patch_libredirect/Cargo.toml \
-- \
--warn clippy::all \
--warn clippy::cargo \
--warn clippy::nursery \
--warn clippy::pedantic \
--warn clippy::restriction \
;

RUN \
PATH="$HOME/.cargo/bin:$PATH" \
cargo run \
--manifest-path ./rust/wolfree_patch_libredirect/Cargo.toml \
-- \
;

# Create a webpage that lists all repositories and instructions for self-hosting web services.

COPY \
./README.md \
./README.md

RUN \
cat \
-- \
./README.md \
>> \
./docusaurus/docs/source.mdx \
;

# Use Docusaurus to build the static website.

RUN \
npm \
--prefix ./docusaurus/ \
-- \
run \
build \
;

# Host the static content with a webserver.

CMD \
npm \
--prefix ./docusaurus/ \
-- \
run \
serve \
--host localhost \
--port 80 \
;

EXPOSE 80

# TODO: multi-stage
# https://docs.docker.com/build/building/multi-stage/
# https://docs.docker.com/build/guide/multi-stage/

# Optimizing builds with cache management | Docker Documentation
# https://docs.docker.com/build/cache/
# Because a change causes a rebuild for steps that follow,
# try to make expensive steps appear near the beginning of the Dockerfile.
# Steps that change often should appear near the end of the Dockerfile to avoid triggering rebuilds of layers that haven't changed.